package cn.clementine.core.api;

import cn.clementine.core.crud.CustomerCrud;
import cn.clementine.core.entity.DiskInfo;
import cn.clementine.core.entity.MemInfo;
import cn.clementine.core.entity.OSInfo;
import cn.clementine.core.svc.WebShell;
import cn.clementine.core.vo.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.management.ManagementFactory;
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;

@RestController
public class MainController {
    @Resource
    CustomerCrud customerCrud;
    @Resource
    WebShell webShell;
    @GetMapping("/get_os_info")
    public Result getOsName(){
        return Result.ok(new OSInfo());
    }
    @GetMapping("/get_disk_info")
    public Result getDiskInfo(){
        return Result.ok(new DiskInfo().getDiskInfo());
    };
    @GetMapping("/get_all_user")
    public Result getAllUser(){
        return Result.ok(customerCrud.findAll());
    }

    @GetMapping("/get_all_env_path")
    public Result getAllPath(){ return Result.ok(System.getenv());}

    @GetMapping("/get_operating_system_MXBean")
    public Result getOperatingSystemMXBean(){
        return Result.ok(new MemInfo());
    }

    @GetMapping("/all_threads")
    public Result getAllThreads(){
        var res = Arrays.stream(ManagementFactory.getThreadMXBean().dumpAllThreads(true, true)).map((e)->
            new ThreadInfoView(
                    e.getThreadName(),
                    e.getThreadId(),
                    e.getBlockedTime(),
                    e.getBlockedCount(),
                    e.getWaitedTime(),
                    e.getWaitedCount(),
                    e.getLockName(),
                    e.getLockOwnerId(),
                    e.getLockOwnerName(),
                    e.isDaemon()
                    ,e.isInNative()
                    ,e.isSuspended()
                    ,e.getThreadState(),
                    e.getPriority(),
                    e.getLockedMonitors(),
                    e.getLockedSynchronizers(),
                    e.getLockInfo())
        );
        return Result.ok(res);
    }


}
